package com.lpc.dagger2test;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.lpc.dagger2test.component.AppComponent;
import com.lpc.dagger2test.component.DaggerMainComponent;
import com.lpc.dagger2test.component.MainComponent;
import com.lpc.dagger2test.bean.Student;
import com.lpc.dagger2test.bean.User;
import com.lpc.dagger2test.module.UserModule;

import javax.inject.Inject;
import javax.inject.Named;

import dagger.Lazy;

public class MainActivity extends BaseActivity {

    @Inject
    User user;

    @Inject
    User user2;

    @Named("None")
    @Inject
    Student student;

    @Named("Context")
    @Inject
    Student student2;

    private Button btn3;
    private Button btn2;
    private Button btn1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MainComponent mainComponent = DaggerMainComponent.builder()
                .appComponent(appComponent)
                .userModule(new UserModule())
                .build();
        mainComponent.inject(this);

        init();
    }

    private void init() {

        btn1 = findViewById(R.id.btn1);
        btn2 = findViewById(R.id.btn2);
        btn3 = findViewById(R.id.btn3);
        btn1.setText("user " + user.toString());
        btn2.setText("user2 " + user2.toString());
        btn3.setText("student " + student.getSex() + student.getNum() + "\n"
                + "student2 " + student2.getSex() + student2.getNum());

    }

    public void click1(View view) {

        startActivity(new Intent(this, MainActivity.class));
    }

    public void click2(View view) {

    }

    public void click3(View view) {


    }
}
